package com.tfjybj.itoo.exam.provider.service.impl;

import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.StudentScoreEntity;
import com.tfjybj.itoo.exam.model.StudentScoreModel;
import com.tfjybj.itoo.exam.provider.dao.StudentScoreDao;
import com.tfjybj.itoo.exam.provider.service.StudentScoreService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;


/**
 * StudentScoreService接口实现类
 * ${base}表
 *
 * @author 任晓帅
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 19:40:28
 */
@Service("studentScoreService")
public class StudentScoreServiceImpl extends BaseServicePlusImpl<StudentScoreDao, StudentScoreEntity> implements StudentScoreService {

    //region 模板生成
    @Resource
    private StudentScoreDao studentScoreDao;


    @Override
    public PageInfo<StudentScoreEntity> queryByLikeStudentCode(String studentCode, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(studentScoreDao.queryLikeStudentCode(studentCode));
    }


    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    @Override
    public int queryIsExistScore(String exameeId, String examionId) {
        return studentScoreDao.queryIsExistScore(exameeId, examionId);
    }

    @Override
    @Transactional(rollbackOn = Exception.class)
    public List<StudentScoreEntity> upStudentScore(StudentScoreModel stuScore) {
        List<StudentScoreEntity> stuList = studentScoreDao.selPaperDetails(stuScore);
        for (StudentScoreEntity stu : stuList) {
            StudentScoreEntity studentScoreEntity = new StudentScoreEntity();
//            studentScore.setStudentScore(String.valueOf(Integer.parseInt(stu.getStudentScore()) + stuScore.getAddScore()));
//            String gss=stu.getStudentScore();
////            BigInteger a=new BigInteger(gss);
//            double a=Double.valueOf(gss.trim());
//            double b=a+stuScore.getAddScore();
//            String score=String.valueOf(b);
            studentScoreEntity.setStudentScore(stuScore.getStudentScore());
            studentScoreEntity.setId(stu.getId());
            studentScoreEntity.setExamineeId(stu.getExamineeId());
            studentScoreEntity.setTemplateId(stu.getTemplateId());
            this.studentScoreDao.updateById(studentScoreEntity);
        }
        return studentScoreDao.selPaperDetails(stuScore);
    }

    @Override
    public List<StudentScoreModel> selectlowclass(String number, String operator) {

        return studentScoreDao.selectlowclass(number, operator);
    }

    @Override
    public List<StudentScoreModel> selectlowstudent(String number, String templateId, String classId, String operator) {
        return studentScoreDao.selectlowstudent(number, templateId, classId, operator);
    }



}

